
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;
using Evaluant.Uss.ObjectContext.Descriptors;

    

namespace NUnit.MappingGenerator
{
	
	public enum   Title 
	{ 
		Miss,
		Madam,
		Sir
	}
	
	public partial interface IPerson
	{
		string Id { get; set; }
		string  Name { get; set; }
		string  FirstName { get; set; }
		System.Int32  Age { get; set; }
		
		IAddress  Address { get; }
		Title  Title { get; set; }
		
	}
	
  
  [Serializable]
  public partial class PersonCollection : IPersistableCollection<Person>
	{
		public PersonCollection() : base()
    {
    }

    public PersonCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Person> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Person :  IPersistable, IPerson 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_Address != null)
				_PersistenceManager.TrackObject(_Address);
		
		}
		
	
    protected string _Name;

    public string Name
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Name"))
          _Name = (string)this._Entity["Name"];
          
        return _Name;
      }

      set
      {
        _Name = value;
        if(_Entity != null)
			this._Entity["Name"] = value;
      }
    }
    
    protected string _FirstName;

    public string FirstName
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("FirstName"))
          _FirstName = (string)this._Entity["FirstName"];
          
        return _FirstName;
      }

      set
      {
        _FirstName = value;
        if(_Entity != null)
			this._Entity["FirstName"] = value;
      }
    }
    
    protected System.Int32 _Age;

    public System.Int32 Age
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Age"))
          _Age = (System.Int32)this._Entity["Age"];
          
        return _Age;
      }

      set
      {
        _Age = value;
        if(_Entity != null)
			this._Entity["Age"] = value;
      }
    }
    
		
		[NonSerialized]
		private bool _IsAddressLoaded = false;

		protected Address _Address;

		public Address  Address
		{
			get 
			{ 
            if(!_IsAddressLoaded && _PersistenceManager != null && _Entity != null)
            {
            // Inferred relationships
            Entity entity = _Entity.GetEntity("Address");
            IList items = null;
            if(entity == null)
            {
                if(_Entity.InferredReferences.Contains("Address"))
                    _Address = null;
                else
                    items = _PersistenceManager.LoadReference(_Entity, "Address");
            }
            else
            {
                items = _PersistenceManager.LoadWithEntities<Address>(new EntitySet( new Entity[] { entity }));
            }

            if(items != null && items.Count > 0)
              _Address = (Address)items[0];

            _IsAddressLoaded = true;
        }

        return _Address;
			}			
			set
			{
				// Removes the reference to an existing entity
				if(Address != null && _Entity != null)
				{
					_Entity.DeleteElement("Address");
				}
				
				// Creates the reference only if it is a concrete entity
				if(value != null && _Entity != null)
				{
					_Entity.AddValue("Address", ((IPersistable)value).Entity);
				}
				
				_Address = value;
			}
		}			
			
    protected Title   _Title;

      [PersistentProperty("_Title", true)]
      public Title   Title
    {
      get
      {
		    if(_Entity != null)
		    {
			    if(_Entity.IsNull("Title"))
				    _Title = default(Title);
          else
            _Title = (Title)Enum.Parse(typeof(Title), (string)this._Entity["Title"]);
        }

        return _Title;
      }

      set
      {
        _Title = value;
        if(_Entity != null)
            this._Entity["Title"] = Enum.GetName(typeof(Title), value);
      }
    }
      
		IAddress IPerson.Address
		{
			get { return Address; }
		}
		
		public Person ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Person (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IChairman
	{
		string Id { get; set; }
		string  CompanyName { get; set; }
		
		IEnumerable<IEmployee>  Employees { get; }

	}
	
  
  [Serializable]
  public partial class ChairmanCollection : IPersistableCollection<Chairman>
	{
		public ChairmanCollection() : base()
    {
    }

    public ChairmanCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Chairman> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Chairman : Person, IPersistable, IChairman 
	{		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_Employees != null)
				_PersistenceManager.TrackObject(_Employees);
		
			if(_Address != null)
				_PersistenceManager.TrackObject(_Address);
		
		}
		
	
    protected string _CompanyName;

    public string CompanyName
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("CompanyName"))
          _CompanyName = (string)this._Entity["CompanyName"];
          
        return _CompanyName;
      }

      set
      {
        _CompanyName = value;
        if(_Entity != null)
			this._Entity["CompanyName"] = value;
      }
    }
    
    protected EmployeeCollection _Employees;

    [PersistentProperty("_Employees", false)]
    public EmployeeCollection Employees
    {
      get
      {
        if(_Employees == null)
        {
          // Inferred relationships
          EntitySet entities = _Entity.GetEntitySet("Employees");
          List<Employee> items = entities.Count == 0 ? null : _PersistenceManager.LoadWithEntities<Employee>(entities);

          _Employees = new EmployeeCollection(_PersistenceManager, this, "Employees", items);
        }
        return _Employees;
      }

      set // Defined for Serializable() compatibility only
      {
        _Employees = value;
      }
    }

		IEnumerable<IEmployee> IChairman.Employees
		{	                
			get 
			{ 
				foreach(IEmployee item in Employees) 
					yield return item;
			}
		}
	
		public Chairman ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Chairman (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public new class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IEmployee
	{
		string Id { get; set; }
		int  Salary { get; set; }
		
	}
	
  
  [Serializable]
  public partial class EmployeeCollection : IPersistableCollection<Employee>
	{
		public EmployeeCollection() : base()
    {
    }

    public EmployeeCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Employee> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Employee : Person, IPersistable, IEmployee 
	{		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
			if(_Address != null)
				_PersistenceManager.TrackObject(_Address);
		
		}
		
	
    protected int _Salary;

    public int Salary
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Salary"))
          _Salary = (int)this._Entity["Salary"];
          
        return _Salary;
      }

      set
      {
        _Salary = value;
        if(_Entity != null)
			this._Entity["Salary"] = value;
      }
    }
    
		public Employee ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Employee (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public new class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface IAddress
	{
		string Id { get; set; }
		string  City { get; set; }
		System.String  Street { get; set; }
		int  PostCode { get; set; }
		
	}
	
  
  [Serializable]
  public partial class AddressCollection : IPersistableCollection<Address>
	{
		public AddressCollection() : base()
    {
    }

    public AddressCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<Address> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class Address :  IPersistable, IAddress 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
	
    protected string _City;

    public string City
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("City"))
          _City = (string)this._Entity["City"];
          
        return _City;
      }

      set
      {
        _City = value;
        if(_Entity != null)
			this._Entity["City"] = value;
      }
    }
    
    protected System.String _Street;

    public System.String Street
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("Street"))
          _Street = (System.String)this._Entity["Street"];
          
        return _Street;
      }

      set
      {
        _Street = value;
        if(_Entity != null)
			this._Entity["Street"] = value;
      }
    }
    
    protected int _PostCode;

    public int PostCode
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("PostCode"))
          _PostCode = (int)this._Entity["PostCode"];
          
        return _PostCode;
      }

      set
      {
        _PostCode = value;
        if(_Entity != null)
			this._Entity["PostCode"] = value;
      }
    }
    
		public Address ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Address (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}
	
	public partial interface ITransportHeader
	{
		string Id { get; set; }
		System.String  TransportHeaderId { get; set; }
		System.Int32  TransportOrder { get; set; }
		DateTime  DeliveringDate { get; set; }
		System.Int32  TransporterNumber { get; set; }
		
	}
	
  
  [Serializable]
  public partial class TransportHeaderCollection : IPersistableCollection<TransportHeader>
	{
		public TransportHeaderCollection() : base()
    {
    }

    public TransportHeaderCollection (ObjectContext persistenceManager, IPersistable parent, string role, IEnumerable<TransportHeader> data): base(persistenceManager, parent, role, data)
    {
    }
	}

	[Serializable]
	public partial class TransportHeader :  IPersistable, ITransportHeader 
	{		
	
		[NonSerialized]
		protected Entity _Entity;
		
		[NonSerialized]
		protected ObjectContext _PersistenceManager;
		
		Entity IPersistable.Entity
		{
			get
			{
				return _Entity;
			}
			set
			{
				_Entity = value;
			}
		}
		
		ObjectContext IPersistable.ObjectContext
		{
			get
			{
				return _PersistenceManager;
			}
			set
			{
				_PersistenceManager = value;
			}
		}
		
		public string Id
		{
			get
			{
				return _Entity.Id;
			}
			set
			{
				_Entity.Id = value;
			}
		}
		
	
		void IPersistable.TrackChildren()
		{
			// if the object is not tracked there is nothing to do
			if(_PersistenceManager == null)
				return;
	
		}
		
	
    protected System.String _TransportHeaderId;

    public System.String TransportHeaderId
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("TransportHeaderId"))
          _TransportHeaderId = (System.String)this._Entity["TransportHeaderId"];
          
        return _TransportHeaderId;
      }

      set
      {
        _TransportHeaderId = value;
        if(_Entity != null)
			this._Entity["TransportHeaderId"] = value;
      }
    }
    
    protected System.Int32 _TransportOrder;

    public System.Int32 TransportOrder
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("TransportOrder"))
          _TransportOrder = (System.Int32)this._Entity["TransportOrder"];
          
        return _TransportOrder;
      }

      set
      {
        _TransportOrder = value;
        if(_Entity != null)
			this._Entity["TransportOrder"] = value;
      }
    }
    
    protected DateTime _DeliveringDate;

    public DateTime DeliveringDate
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("DeliveringDate"))
          _DeliveringDate = (DateTime)this._Entity["DeliveringDate"];
          
        return _DeliveringDate;
      }

      set
      {
        _DeliveringDate = value;
        if(_Entity != null)
			this._Entity["DeliveringDate"] = value;
      }
    }
    
    protected System.Int32 _TransporterNumber;

    public System.Int32 TransporterNumber
    {
      get
      {
        if(_Entity != null && !_Entity.IsNull("TransporterNumber"))
          _TransporterNumber = (System.Int32)this._Entity["TransporterNumber"];
          
        return _TransporterNumber;
      }

      set
      {
        _TransporterNumber = value;
        if(_Entity != null)
			this._Entity["TransporterNumber"] = value;
      }
    }
    
		public TransportHeader ()
		{
			
			this._Entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public TransportHeader (Entity e)
		{
			this._Entity = e;
		}

		[Serializable]
		public class ParentRelationships
		{
			private IPersistable _Owner;
	
			public ParentRelationships()
			{
			}
			
			public ParentRelationships(IPersistable o)
			{
				_Owner = o;
			}
		
		}
	}

}
